<?php
	define('DT_NONUSER', true);
	error_reporting(0);
//if($_SERVER['QUERY_STRING'] && strpos($_SERVER['QUERY_STRING'], '$') === false) {

	require '../common_ccb.inc.php';

 
	//require '../config.inc.php';
	require  '../include/ccb.func.php';
	//require  '../include/ccb.class.php';
	log_write ( '', 'api' );
	$ccb=new ccb();
	
	// 接收推送信息
	$xml = $_POST['xml'];
	$signature = $_POST ['signature'];

	
	//$key='I08xwa3xg14Iq0z7FexD/SNPMcGt8YNe';
	//log_write ( $xml, 'api' );
	// 取得交易码
	//  $key='sLYgO4YNomGt44aUH7+1YrC2IDuGDaJh';
	$xml=$ccb->decrypt(base64_decode($xml));
	//log_write ( '银行->商户'.$xml, 'ccb' );
	$xml=str_replace('gb2312', 'utf-8', $xml);
	//echo $xml;
	//$array = (array)(simplexml_load_string($xml));
	//var_dump($array );
	@$data=$ccb->XMLtoArray($xml);
	//var_dump($data);
	$trad_code = $data['HEAD']['chanl_trad_no'];
	log_write ( $xml, $trad_code );
	//echo $xml;
	//调用方法
	$trad_code='ccb_'.$trad_code;
	//echo $trad_code;
	//返回数组
	@$rtData =  $trad_code($data);
	//var_dump($rtData);
	//转为xml报文
	@$putXml=$ccb->ArraytoXML($rtData);
	//$putXml = iconv("utf-8", "GBK", $putXml);
	//$putXml = mb_convert_encoding($putXml, 'GBK','utf-8');
	//log_write ( $xml. $putXml, $trad_code );
	//echo $putXml;
	/*$putXml='<?xml version="1.0" encoding="gb2312" ?>
				<message>
					<head>
							<field name="version"><![CDATA[100]]></field>
							<field name="type"><![CDATA[0210]]></field>
							<field name="chanl_no"><![CDATA[30]]></field>
							<field name="chanl_sub_no"><![CDATA[3001]]></field>
							<field name="chanl_date"><![CDATA[20120419]]></field>
							<field name="chanl_time"><![CDATA[100140]]></field>
							<field name="ectip_date"><![CDATA[20120419]]></field>
							<field name="chanl_flow_no"><![CDATA[20120419100140]]></field>
							<field name="ectip_flow_no"><![CDATA[20120419100140]]></field>
							<field name="chanl_trad_no"><![CDATA[3FC003]]></field>
							<field name="term_inf"><![CDATA[15.128.33.9]]></field>
							<field name="resp_code"><![CDATA[000000000000]]></field>
							<field name="resp_msg"><![CDATA[SUCCESS]]></field>
							<field name="page">0</field>
							<field name="maxrow"></field>
							<field name="locstr"></field>
							<field name="tot_rec"></field>
					</head>
					<body>
					</body>
				</message>';*/
	$putXml = iconv("utf-8", "GBK", $putXml);
	$signature=$ccb->sign($putXml);
	$encXml=$ccb->encrypt($putXml);
	//$signature = $signature;
	//$encXml = $encXml;
	$putMSG = '0000000'.strlen($signature).$signature.$encXml;
	
	// $putMSG = mb_convert_encoding($putMSG, 'GB2312','utf-8');
	
	echo   $putMSG;
	?>